package com.ilia.leek.fund.eastmoney;

import cn.hutool.core.util.ObjectUtil;
import com.dtflys.forest.http.ForestResponse;
import com.ilia.leek.common.enums.ResultCode;
import com.ilia.leek.common.exception.BaseBusinessException;
import com.ilia.leek.fund.FundConstant;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author Alice on 2021/4/26
 * @version 1.0
 * @since 1.0
 */
@Component
@Slf4j
public class HttpFundgzFund {

    @Resource
    private EastmoneyHttpClient eastmoneyHttpClient;

    /**
     * 查询天天基金网的实时基金数据
     * e:http://fundgz.1234567.com.cn/js/001186.js?rt=1463558676006
     *
     * @return String
     */
    public String getRealTime(String code) {
        ForestResponse<String> result = eastmoneyHttpClient.fundzRealTime(FundConstant.FUNDGZ_REAL_TIME + "/" + code + ".js?rt=" + System.currentTimeMillis());
        if (!ObjectUtil.isEmpty(result.getContent())) {
            return result.getContent();
        }
        throw new BaseBusinessException(ResultCode.NET_ERROR);
    }
}
